package com.example.mymatch.service.Imp;

import com.example.mymatch.dao.ILeave;
import com.example.mymatch.model.Leave;
import com.example.mymatch.service.ILeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对服务接口规范的方法实现
 * 编写者：杨滢
 */

@Service
public class ILeaveServiceImpl implements ILeaveService {

    @Autowired
    private ILeave leaveMapper;

    @Override
    public int insertLeave(Leave leave){
        int leaveValue=0;
        //查看当前用户名称不能重复
        Leave leave1=new Leave();
        leave1.setLeaveName(leave.getLeaveName());
        List<Leave> getC=leaveMapper.getAllLeave(leave1);
        if (getC.size()>=1){
            //不可以添加用户名称
            leaveValue=-1;
        }else {
            leaveValue=leaveMapper.insertLeave(leave);
        }
        return leaveValue;
    }

    @Override
    public List<Leave> getAllLeave(Leave leave){
        return leaveMapper.getAllLeave(leave);
    }

    @Override
    public int updateLeave(Leave leave){
        int leaveValue=0;
        //判断主键不能为0
        if (leave.getId()!=0){
            //主键信息必修存在
            //名称不能重复
            leaveValue=leaveMapper.updateLeave(leave);
        }
        return leaveValue;
    }

    @Override
    public  int deleteLeave(Leave leave){
        int leaveValue=0;
        //判断主键不能为0
        if (leave.getId()!=0){
            //主键是否有其他表有关联，如果关联，则先删除其他表的信息，或者给出此条信息不允许被删除
            leaveValue=leaveMapper.deleteLeave(leave);
        }
        return leaveValue;
    }

    //单条查询
    @Override
    public Leave getLeave(Leave leave){
        Leave leave1=new Leave();
        if (leave.getId()!=0){
            leave1=leaveMapper.getLeave(leave);
        }
        return leave1;
    }
}
